#include<p18f4550.h>
#include<plib/delays.h>
#include<plib/xlcd.h>


void DelayFor18TCY(){Delay10TCYx(10);}
void DelayPORXLCD(){Delay10KTCYx(2);}
void DelayXLCD(){Delay1KTCYx(5);}

void main(){

    int D,U,T1,T2,TP,TA=0;

    ADCON1=13;ADCON2=128;//CONFIGURACION DEL ADC
    TRISB=0;
    while(BusyXLCD());
    OpenXLCD(FOUR_BIT&LINES_5X7);
    WriteCmdXLCD(0X01);
    SetDDRamAddr(0x00);
    Delay100TCYx(100);
    putrsXLCD("TEMPERATURA");
    SetDDRamAddr(0x40);
    Delay100TCYx(100);
    putrsXLCD("MUFLA: ");

    while(1){

            ADCON0=3; while(ADCON0bits.GO);
            T1=(ADRESL*4.886)/10;
            ADCON0=7; while(ADCON0bits.GO);
            T2=(ADRESL*4.886)/10;
            TP=(T1+T2)/2;
            if(TP!=TA) {
                TA=TP;
                D=TP/10;
                U=TP%10;
                SetDDRamAddr(0x47);
                Delay100TCYx(100);
                WriteDataXLCD(0x30+D);
                Delay100TCYx(100);
                WriteDataXLCD(0x30+U);
                Delay100TCYx(100);
                putrsXLCD("       ");
            }//FIN IF
    }//FIN WHILE
}//FIN PROGRAMA
